//<script type='text/javascript'>

////////////////////////////////////////// EXTENTION: BAR: BUBBLE
var Bubble = function ( string ) {
	Object.extend( bubble = new Element("div", { "class":'ext bubble', style:'opacity:0' }).update( string ), dashboard.ext.bubble);
	
	return bubble.settime( 2 );
}

dashboard.ext.bubble	= {
	all		: 0,
	settime	: function( n ) {
		this.appear({ duration: 0.2 });
		setTimeout( function( bubble ){ bubble.fade({ duration: 4 }); }, n*1000, this);
		setTimeout( function( bubble ){ bubble.remove(); }, (n+4)*1000, this);
		return this;
	}
}

////////////////////////////////////////// EXTENTION: BAR: TOOLTIP
var Tooltip = function ( target, content, classname, stay ) {
	
	if( $('tooltip'))
		tooltip = $('tooltip').remove().toggleClassName( 'ext tooltip '+ classname );
	else
		Object.extend( tooltip = new Element("div", { id:'tooltip', 'class':'ext tooltip '+ classname, style:'opacity:0' }), dashboard.ext.tooltip );
	
	tooltip.seed( content ).appear({ duration: .2 });
	
	if( !stay )
		target.observe( "mouseout", tooltip.fade.bind( tooltip, { duration: .8 }));
			
	return tooltip.clonePosition( target, { setWidth: false, setHeight: false, offsetTop:-2, offsetLeft:-2 });
}

dashboard.ext.tooltip	= {
	
	seed			: function( content ) {
		
		if( typeof content == "object" ) {
			content.each( function( el ){ this.insert(( typeof el == "object" )? el : new Element( "span" ).update( el )); }, this.update());
			this.insert( new Element( "div", { 'class': "stable" }));
		} else this.update( content );
		
		return this;
	}
}


/////// EXTENTION: DASHBOARD UNIT
var Unit = function ( descr, type, columns ) {
	if( !type ) type = "ul";
	
	Object.extend( unit = new Element( "div", { 'class': "unit" + (( columns )? " columns" + columns : "" )}), dashboard.ext.unit );

	unit.insert( new Element( "div", { 'class': "scroll" }).hide().insert( new Element( "div", { 'class': "handle" }))); //.observe( "click", unit.scroll.bind( unit ))
	
	if( descr )
		unit.insert( unit.descr = new Element( "h1", { 'class': "descr" }).update( descr ));
		
	unit.insert( new Element( "div", { 'class': "content" }).insert( unit.content = new Element( type )));
	unit.insert( new Element( "div", { 'class': "stable" }));
	
	return unit;
}

dashboard.ext.unit	= {
	enableScroll : function( height ) {
		
		this.setStyle({ height: height + "px", overflow: "hidden" });

		this.calcHandle();
		
		new Control.Slider(this.down( ".handle" ), this.down( ".scroll" ), {
      		axis	: "vertical",
      		range	: $R(0, 100),
     		sliderValue: 0,
      		onSlide: this.scroll.bind( this ),
      		onChange: this.scroll.bind( this )
    	});
		
		return this;
	},
	
	calcHandle	: function() {
		thisH		= this.getHeight();
		contentH	= this.content.getHeight();
		
		if( thisH < contentH )
			 this.down( ".scroll" ).show().down( ".handle" ).setStyle({ height: Math.round( thisH * ( thisH / contentH )) + "px" });
		else this.down( ".scroll" ).hide();
		
		this.content.difference = contentH + 42 - thisH;
	}, 
	
	scroll 		: function( value ) {

		this.content.setStyle({ top: -Math.round( this.content.difference * value / 100) + "px" });
	},
	
	insertli 	: function( el ) {

		this.content.insert( new Element( "li" ).update( el ));
	}
}


/////// EXTENTION: DASHBOARD INFO
var Info = function ( descr, type, columns ) {
	if( !type ) type = "ul";
	
	Object.extend( info = new Element( "div", { id:"info" }), dashboard.ext.info );
	
	info.insert( info.column = new Element( "div", { 'class': "column" }));
	info.insert( new Element( "div", { 'class': "scroll" }).hide().insert( new Element( "div", { 'class': "handle" }))); //.observe( "click", unit.scroll.bind( unit ))
	
	if( descr )
		info.insert( info.descr = new Element( "h1", { 'class': "descr" }).update( descr ));
		
	info.insert( new Element( "div", { 'class': "content" }).insert( info.content = new Element( type )));
	info.insert( new Element( "div", { 'class': "stable" }));
	
	return info;
}

dashboard.ext.info	= {
	enableScroll : function( height ) {
		
		this.setStyle({ height: height + "px", overflow: "hidden" });

		this.calcHandle();
		
		new Control.Slider(this.down( ".handle" ), this.down( ".scroll" ), {
      		axis	: "vertical",
      		range	: $R(0, 100),
     		sliderValue: 0,
      		onSlide: this.scroll.bind( this ),
      		onChange: this.scroll.bind( this )
    	});
		
		return this;
	},
	
	calcHandle	: function() {
		thisH		= this.getHeight();
		contentH	= this.content.getHeight();
		
		if( thisH < contentH )
			 this.down( ".scroll" ).show().down( ".handle" ).setStyle({ height: Math.round( thisH * ( thisH / contentH )) + "px" });
		else this.down( ".scroll" ).hide();
		
		this.content.difference = contentH + 42 - thisH;
	}, 
	
	scroll 		: function( value ) {

		this.content.setStyle({ top: -Math.round( this.content.difference * value / 100) + "px" });
	}
}
